package cn.jdy.platform.tag;

import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.SpringContextUtils;
import cn.jdy.platform.service.ConfService;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * 获取配置信息
 *
 * @description :
 * @author: zhaiguangtao
 * @data: 2010-8-9
 */
public class CacheTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private String typeid;// 对应配置项目  typeid
	private String key;// 配置key

	@Override
	public int doStartTag() throws JspException {// 这个方法不用所以直接返回值
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {// 重点在这个方法上
		try {
			ConfService conf = SpringContextUtils.getBean(ConfService.class);
			String res = conf.findConfVal(typeid, key);
			JspWriter out = pageContext.getOut();
			out.print(res == null ? "" : res);// 标签的返回值
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "", e);
		}
		return EVAL_PAGE;
	}

	public String getTypeid() {
		return typeid;
	}

	public void setTypeid(String typeid) {
		this.typeid = typeid;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}
}
